new Vue({
    el: '#app',
    data() {
        return {
            id:'',
            formData: {},
        }
    },
    beforeCreate() {
        function setRem() {
            const designWidth = 750; // 设计稿宽度（rpx）
            const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
            const screenWidth = Math.min(window.innerWidth, maxWidth);
            const scale = screenWidth / designWidth;
            document.documentElement.style.fontSize = scale + 'px';
        }
        setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
    },
    mounted() {
        let URL = window.location.href;
        this.id = getQueryObject(URL, 'id');
        this.init();
    },
    methods: {
        async init(callback) {
            await Promise.allSettled([
                this.getList(),
            ]);
            callback ? callback() : null;
        },
        async getList() { // 商品信息
            try {
                const data = await generalApi.generalQueryBySQLSerialNumberWithClient({
                    SQLSerialNumber: 't_supply_hall',
                    Condition: utf8ToBase64(`%%,%%`),
                    ExtensionCondition: utf8ToBase64(`AND supply_unitprice.Supply_Unit_Price_SerialNumber='${this.id}'`)
                })
                if (data.length == 1) {
                    this.formData = data[0];
                }
            } catch (error) {
                console.error(error);
            }
        },
        handleAdd() {// 申请
            if (this.formData.Enterprise_Info_SerialNumber != getCookie('enterprise')) {
                window.location.href = `../../pages/submit/supply-submit.html?id=${this.id}`;
            } else {
                this.$showToast({
                    title: '本企发布，无法下单！'
                });
            }
        }
    },
})
